package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    List<User> selectList(UserDto userDto);

    @Insert("insert into user(id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time) " +
            "values (#{id},#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void add(User user);

    void deleteById(List<Integer> ids);

    @Update("update user set username=#{username},password=#{password},name=#{name},phone=#{phone},email=#{email},gender=#{gender},status=#{status},dept_id=#{deptId},role_id=#{roleId},image=#{image},remark=#{remark},update_time=#{updateTime} where id=#{id}")
    void update(User user);

    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user where id= #{id}")
    User getById(Integer id);

    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user")
    List<User> getAllList();

    List<User> getByRole(String roleLabel);

    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user where dept_id=#{deptId}")
    List<User> getByDeptId(Integer deptId);

    @Select("select u.*,r.label roleLabel from user u left join role  r on u.role_id = r.id where username =#{username};")
    User getByUsername(String username);
}
